package datagenerator;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Random;

public class DataDriver {

	public static void main(String[] args) {
		Random r = new Random();
		DataGenerator gen = new DataGenerator();
		ArrayList<String[]> workers = new ArrayList<String[]>();
		ArrayList<String[]> pastures = new ArrayList<String[]>();
		ArrayList<String[]> fields = new ArrayList<String[]>();
		ArrayList<String[]> animals = new ArrayList<String[]>();
		ArrayList<String[]> herds = new ArrayList<String[]>();
		ArrayList<String[]> feeds = new ArrayList<String[]>();
		ArrayList<String[]> managers = new ArrayList<String[]>();

		for (int i = 0; i < 1000; i++) {
			workers.add(gen.getWorker());
		}
		for (int i = 0; i < 20; i++) {
			pastures.add(gen.getPasture());
		}
		for (int i = 0; i < 50; i++) {
			fields.add(gen.getField());
		}
		for (int i = 0; i < 600; i++) {
			animals.add(gen.getAnimal());
		}
		for (int i = 0; i < 10; i++) {
			herds.add(gen.getHerd());
		}
		for (int i = 0; i < 10; i++) {
			feeds.add(gen.getFeed());
		}
		for (int i = 0; i < 9; i++) {
			managers.add(gen.getManager());
		}
		File fout = new File("output.txt");
		if (fout.exists()) {
			fout.delete();
		}
		try {
			FileWriter f = new FileWriter("output.txt", true);
			PrintWriter p = new PrintWriter(f);
			p.println("USE [EFPAG]\nGO\n");
			p.println("SET IDENTITY_INSERT Worker ON;\nGO");
			for (String[] s : workers) {
				String print = "INSERT INTO Worker (WID, Pay, Name, Position, WorkShift)\n	VALUES("
						+ s[0]
						+ ", "
						+ s[1]
						+ ", '"
						+ s[2]
						+ "', '"
						+ s[3]
						+ "', " + s[4] + ");";
				p.println(print);
			}
			for (String[] s : managers) {
				String print = "INSERT INTO Worker (WID, Pay, Name, Position, WorkShift)\n	VALUES("
						+ s[0]
						+ ", "
						+ s[1]
						+ ", '"
						+ s[2]
						+ "', '"
						+ s[3]
						+ "', " + s[4] + ");";
				p.println(print);
			}
			int dept = 0;
			String[] depts = new String[] { "Field Worker", "Animal Worker",
					"Vet", "Animal Breeder", "Grader", "Sorter", "Inspector",
					"Horticulturist", "Management" };
			for (String[] s : managers) {
				for (String[] w : workers) {
					if (w[3].equals(depts[dept])) {
						String print = "INSERT INTO [Supervised By] (Supervisor, Worker)\n	VALUES("
								+ s[0] + ", " + w[0] + ");";
						p.println(print);
					}
				}
				dept++;
			}
			p.println("SET IDENTITY_INSERT Worker OFF;\nGO");
			p.println("SET IDENTITY_INSERT Pasture ON;\nGO");
			for (String[] s : pastures) {
				String print = "INSERT INTO Pasture (PID, DateOpened, Location, Name)\n	VALUES("
						+ s[0]
						+ ", '"
						+ s[1]
						+ "', '"
						+ s[2]
						+ "', '"
						+ s[3]
						+ "');";
				p.println(print);
			}
			p.println("SET IDENTITY_INSERT Pasture OFF;\nGO");
			p.println("SET IDENTITY_INSERT Field ON;\nGO");
			for (String[] s : fields) {
				String print = "INSERT INTO Field (FID, Crop, Treatment, DateSeeded, Yield, Location)\n	VALUES("
						+ s[0]
						+ ", '"
						+ s[1]
						+ "', '"
						+ s[2]
						+ "', '"
						+ s[3]
						+ "', " + s[4] + ", '" + s[5] + "');";
				p.println(print);
			}
			p.println("SET IDENTITY_INSERT Field OFF;\nGO");
			p.println("SET IDENTITY_INSERT Animal ON;\nGO");
			for (String[] s : animals) {
				String print = "INSERT INTO Animal (AID, Breed, Purpose, MedStatus, Sex, Age)\n	VALUES("
						+ s[0]
						+ ", '"
						+ s[1]
						+ "', '"
						+ s[2]
						+ "', '"
						+ s[3]
						+ "', '" + s[4] + "', " + s[5] + ");";
				p.println(print);
			}
			p.println("SET IDENTITY_INSERT Animal OFF;\nGO");
			p.println("SET IDENTITY_INSERT Herd ON;\nGO");
			for (String[] s : herds) {
				String print = "INSERT INTO Herd (HID, Manure, Food)\n	VALUES("
						+ s[0] + ", " + s[1] + ", " + s[2] + ");";
				p.println(print);
			}
			p.println("SET IDENTITY_INSERT Herd OFF;\nGO");
			p.println("SET IDENTITY_INSERT Feed ON;\nGO");
			for (String[] s : feeds) {
				String print = "INSERT INTO Feed (DID, Product, Amount, Supplier, Cost)\n	VALUES("
						+ s[0]
						+ ", '"
						+ s[1]
						+ "', "
						+ s[2]
						+ ", '"
						+ s[3]
						+ "', " + s[4] + ");";
				p.println(print);
			}
			p.println("SET IDENTITY_INSERT Feed OFF;\nGO");
			for (String[] s : workers) {
				if (s[3].equals("Field Worker")) {
					String[] field = fields.get(r.nextInt(fields.size()));
					String print = "INSERT INTO [Works On] (Worker, Field)\n	VALUES("
							+ s[0] + ", " + field[0] + ");";
					p.println(print);
				}
			}
			for (String[] s : workers) {
				if (s[3].equals("Animal Worker")) {
					String[] herd = herds.get(r.nextInt(herds.size()));
					String print = "INSERT INTO [Works With] (Worker, Herd)\n	VALUES("
							+ s[0] + ", " + herd[0] + ");";
					p.println(print);
				}
			}
			for (String[] s : herds) {
				String[] pasture = pastures.get(r.nextInt(pastures.size()));
				String print = "INSERT INTO [Pastured] (Herd, Pasture)\n	VALUES("
						+ s[0] + ", " + pasture[0] + ");";
				p.println(print);
			}
			for (String[] s : animals) {
				String[] herd = herds.get(r.nextInt(herds.size()));
				String print = "INSERT INTO [Member] (Herd, Animal)\n	VALUES("
						+ herd[0] + ", " + s[0] + ");";
				p.println(print);
			}
			for (String[] s : herds) {
				String[] feed = feeds.get(r.nextInt(feeds.size()));
				String print = "INSERT INTO [Fed To] (Herd, Feed)\n	VALUES("
						+ s[0] + ", " + feed[0] + ");";
				p.println(print);
			}
			p.close();

		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
